import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  ManyToOne,
  OneToMany,
  PrimaryColumn,
  CreateDateColumn,
  UpdateDateColumn,
  BeforeInsert,
  BeforeUpdate,
} from 'typeorm';
import { User } from './user.entity';
import { Singer } from './singer.entity';
import { ApiProperty } from '@nestjs/swagger';
import * as crypto from 'crypto';
import * as moment from 'moment'; // 修改这里
import { BaseEntity } from './base.entity';

@Entity()
export class VoteRecord extends BaseEntity {
  constructor() {
    super();
    this.id = crypto.randomBytes(8).toString('hex'); // 生成一个8字节（16个十六进制字符）的随机字符串作为id
  }
  @PrimaryColumn({ length: 225 })
  @ApiProperty({
    required: false,
    description: 'id',
  })
  id: string;

  @ManyToOne(() => User, (user) => user.voteRecords, {
    onDelete: 'CASCADE',
  })
  user: User;

  @ManyToOne(() => Singer, (singer) => singer.voteRecords, {
    onDelete: 'CASCADE',
  })
  singer: Partial<Singer>[];

  @Column()
  userId: string; // 将用户ID作为外键存储

  @Column()
  singerId: string; // 将歌手ID作为外键存储
}
